-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add documentation generation functionality #367
Conversation
Tried running this branch on one of my local repos but hit a bug;
This is running against the schema from this PR: aws-cloudformation/aws-cloudformation-resource-providers-cloudformation#4 It's possible that my schema is broken as I haven't finished that, but at the least we probably want to be more tolerant to bad schemas in this doc generation. I think it's a valid schema though, as validation should happen as part of |
TIL you can use composite keys for the primaryIdentifier...will cater for that. Working on the sub-property pages and type detection now. |
@rjlohan Docs generation is now complete. Seeking full review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! will take a look fully next week. there's a bunch of stuff around using pathlib
that would be great to do. although our CI doesn't build Windows yet, would be great to keep it OS agnostic.
if i'm reading it right, i think John did something similar in #315 with cloudformation-cli/src/rpdk/core/contract/resource_generator.py Lines 75 to 76 in 06d5fa9
maybe can use a similar approach? (it isn't ideal since it's an internal class - but we haven't gotten around to write our own, and something already uses it, so fine for now.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do love this feature, but one of my concerns is this feature is opted in by default. I's complex, and simply doesn't work reliably yet when running against real schemas, e.g.:
File "aws-cloudformation-rpdk/src/rpdk/core/templates/docs-readme.yml", line 55, in top-level template code
_Allowed Values_: <code>{{ "</code> | <code>".join(prop.allowedvalues) }}</code>
TypeError: sequence item 0: expected str instance, int found
I also get weird doubling in the sub-property page titles "AWS::Foo::Bar Spam Spam Eggs Eggs" (again, real schema). I'll spend some more time and see if I can debug some of these issues. Do you mind me pushing new commits to this PR, or would you prefer I branch off?
@tobywf Fine for you to make direct edits. Also happy for the docs generation to be opt-in (cfn generate flag?). From memory, when generating sub-property pages I had it generate AWS::Foo::Bar Spam Eggs format (and not just the last element) in order to avoid having two pages of the exact same title - I believe the AWS:: types always have explicit names for these definitions, but this may not be the case in other schemas. Agree the double up is a bug though. |
I'm just going to run it against a bunch of schemas and see what happens. If it works reliably, no need to make it opt-in. |
Okay, fixed the issue with different data types, debugging the duplication. It happens with arrays:
elif prop["type"] == "array":
prop["arrayitems"] = self._set_docs_properties(
propname, prop["items"], proppath
)
An idea is using
But not doing the duplication is what I've gone with for now. |
If you appended |
* Avoid `.join()` in templates; it expects strings only * Use existing functions to decode JSON pointers * Add `.md` to Jinja autoescape settings to prevent HTML injection from e.g. schema descriptions * Also rename templates to correct file-ending of resulting files * Avoid modifying dictionaries in a loop where possible * Check for nested primaryIdentifier * Support nested additionalIdentifiers (but not compound ones) * Make proppath a tuple, so it is immutable * Avoid modifying proppath for type "array" to avoid duplicate propname in proppath * Liberal use of f-strings
awesome, I tried it against a bunch of schemas, and it works great. got a bit carried away, we have functions to parse the JSON pointers. i think we'll try and get this out ASAP in the next release. |
Found another issue: read-only properties should really be excluded, since they can't be specified. |
It could be interesting to include regional availability information here eventually as well Calling the CloudFormation registry directly across multiple partitions with valid credentials doesn't seem practical, but registry type regional availability information might be obtainable through another data source |
…autodoc # Conflicts: # tests/test_project.py
True-up'd with master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one 🥇
Nice work! Tested with one resource, docs looks great: https://gist.github.com/wbingli/f725de6f7950067b250f8f35a8c7ec09 |
{% if prop.createonly %} | ||
|
||
_Update requires_: [Replacement](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-replacement) | ||
{% else %} | ||
|
||
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) | ||
{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're generating documentation, it's probably worth noting nuance for something as important as potential resource replacement. For example, a version property might be upgradable in-place but not downgradable in-place, so neither of these definitions would be entirely accurate. My assumption would be while schema definitions like required
and createOnlyProperties
guarantee a property is required or requires resource replacement to update respectively, other properties not specified as required
or createOnlyProperties
may in fact be required or cause resource replacement under some circumstances. Immutability is important enough that its nuance should probably be captured in the resource schema itself in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BASIC_TYPE_MAPPINGS = { | ||
"string": "String", | ||
"number": "Double", | ||
"integer": "Double", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be Integer
, right?
"integer": "Double", | |
"integer": "Integer", |
@staticmethod | ||
def _get_docs_gettable_atts(docs_schema): | ||
def _get_property_description(prop): | ||
path = fragment_decode(prop, prefix="") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* generate_docs() for conditionalCreateOnlyProperties #367 (comment) aws-cloudformation/cloudformation-resource-schema#121 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-some-interrupt * test coverage
* generate_docs() for conditionalCreateOnlyProperties aws-cloudformation/cloudformation-cli#367 (comment) aws-cloudformation/cloudformation-resource-schema#121 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-some-interrupt * test coverage
Looking for feedback on functionality to add documentation generation during a
cfn generate
. Will generate only initial README.md without correct types for now.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.